package learn.design.patterns.E_Builder.StandardBuilder;

import lombok.Getter;

// 标准建造者模式（Standard Builder Pattern）
// 产品类（Product）
@Getter
class StandardComputer {
    private final String processor;
    private final String ram;
    private final String hardDrive;

    // 构造函数，私有，仅Builder可以访问
    StandardComputer(String processor, String ram, String hardDrive) {
        this.processor = processor;
        this.ram = ram;
        this.hardDrive = hardDrive;
    }

    // ...getter方法...

    // 抽象建造者接口
    interface Builder {
        Builder setProcessor(String processor);
        Builder setRam(String ram);
        Builder setHardDrive(String hardDrive);
        StandardComputer build();
    }

    // 具体建造者
    static class ConcreteBuilder implements Builder {
        private String processor;
        private String ram;
        private String hardDrive;

        @Override
        public Builder setProcessor(String processor) {
            this.processor = processor;
            return this;
        }

        @Override
        public Builder setRam(String ram) {
            this.ram = ram;
            return this;
        }

        @Override
        public Builder setHardDrive(String hardDrive) {
            this.hardDrive = hardDrive;
            return this;
        }

        @Override
        public StandardComputer build() {
            return new StandardComputer(processor, ram, hardDrive);
        }
    }

    // 导演者类
    static class Director {
        StandardComputer constructComputer(Builder builder) {
            return builder.build(); // 这里调用build方法
        }
    }
}
